package lv.rtu.ditf.dc.url;

import java.io.IOException;
import java.net.MalformedURLException;

import lazyj.Util;

/**
 * 
 * @author Pāvels Koliškins, Edgars Matisāns
 *
 */
public class PlainTextPageLoader {
	/**
	 * Reads content from URL.
	 * @param url page URL
	 * @return loaded page content
	 * @throws MalformedURLException if specified URL is invalid 
	 * @throws UnsupportedContentTypeException  if content type of page is not invalid
	 * @throws IOException if general I/O exception occurs
	 */
	public static String loadPage(String url) throws MalformedURLException, UnsupportedContentTypeException, IOException {
		URLDocumentLoader loader = new URLDocumentLoader(url);
		URLDocument doc = loader.loadDocument();
		if (doc.getContent() == null)
			return null;
		else
			return Util.htmlToText(doc.getContent());
	}
	
	public static void main(String[] args) throws Exception {
		System.out.println(loadPage("http://www.delfi.lv/"));
	}
}
